package com.gsd.activemq.spring;

import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.stereotype.Service;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;
import javax.jms.TextMessage;

/**
 * @author guoshoudu
 * @version 1.0
 * @description
 * @date 2021/6/29 5:25 下午
 */
@Service
public class SpringMQ_Produce {
    @Autowired
    private JmsTemplate jmsTemplate;

    public static void main(String[] args) {
        ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
        SpringMQ_Produce produce= (SpringMQ_Produce) ctx.getBean("springMQ_Produce"); //SpringMQ_Produce produce = new SpringMQ_Produce();
//        produce.jmsTemplate.send(new MessageCreator() {
//            @Override
//            public Message createMessage(Session session) throws JMSException {
//                TextMessage textMessage = session.createTextMessage("*********springhe activemq整合case。。。。。。");
//                return textMessage;
//            }
//        });
        produce.jmsTemplate.send((session)-> {
            TextMessage textMessage = session.createTextMessage("*********springhe activemq整合case11111 for MessageListener。。。。。。");
            return textMessage;
        });
        System.out.println("*****send task   ");
    }

}
